package com.yami.shop.multishop.controller;

import com.yami.shop.common.bean.PageDTO;
import com.yami.shop.common.bean.PageVO;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.nft.common.dto.NftDenomDto;
import com.yami.shop.nft.common.model.NftDenom;
import com.yami.shop.nft.common.service.NftDenomService;
import com.yami.shop.security.multishop.util.SecurityUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/admin/nftdenom")
@Tag(name = "admin-链上品类信息")
public class NftDenomController {

    @Autowired
    private NftDenomService nftDenomService;

    @GetMapping("/getdenom")
    @Operation(summary =  "不分页链上品类信息", description = "链上品类信息")
    public ServerResponseEntity<List<NftDenom>> getExandAttrBycate(NftDenomDto nftDenomDto) {
        nftDenomDto.setSysType(1);
        nftDenomDto.setShopId(SecurityUtils.getShopUser().getShopId());
        return ServerResponseEntity.success(nftDenomService.selectNftDenom(nftDenomDto));
    }

    @GetMapping("/getpageDenom")
    @Operation(summary =  "分页获取链上品类信息", description = "分页获取链上品类信息")
    public ServerResponseEntity<PageVO<NftDenom>> getExandAttrByshopId(PageDTO pageDTO, NftDenomDto nftDenomDto) {
        nftDenomDto.setSysType(1);
        nftDenomDto.setShopId(SecurityUtils.getShopUser().getShopId());
        return ServerResponseEntity.success(nftDenomService.pageNftDenom(pageDTO,nftDenomDto));
    }

    @PostMapping
    @Operation(summary =  "保存链上品类信息", description = "保存链上品类信息")
    public ServerResponseEntity<Void> save(@Valid @RequestBody NftDenomDto nftDenomDto) throws IOException {
        nftDenomDto.setSysType(1);
        nftDenomDto.setShopId(SecurityUtils.getShopUser().getShopId());
        nftDenomService.insertDenom(nftDenomDto);
        return ServerResponseEntity.success();
    }

    @GetMapping("/getDenomList")
    @Operation(summary =  "不分页查询未使用得品类列表 0 全部 1 未使用得", description = "不分页查询未使用得品类列表")
    public ServerResponseEntity<List<NftDenom>> getDenomList(@RequestParam("status") Integer status) {
        Long shopId = SecurityUtils.getShopUser().getShopId();
        List<NftDenom> list = nftDenomService.getDenomList(shopId,status);
        return ServerResponseEntity.success(list);
    }

    @GetMapping("/updateDenomStatusByDenomId")
    @Operation(summary =  "修改类别使用状态", description = "修改类别使用状态")
    public ServerResponseEntity updateDenomStatusByDenomId(@RequestParam("denomId")String denomId) {
        nftDenomService.updateDenomStatusByDenomId(denomId);
        return ServerResponseEntity.success();
    }
}
